import Vue from 'vue'
import Vuex from 'vuex'
import axios from '@/api'

import app from './modules/app'
// 登录
// import user from "./modules/user";
// 免登录
// import user from "./modules/user-noauth";

// 静态路由
// import permission from "./modules/permission";
// 动态路由
// import permission from './modules/async-router'

import getters from './getters'

Vue.use(Vuex)

export default new Vuex.Store({
  modules: {
    app
  },
  state: {
    userInfo: {}
  },
  mutations: {
    setUserInfo(state, userInfo) {
      state.userInfo = userInfo
    }
  },
  actions: {
    getUserInfo({ commit }) {
      return new Promise((resolve, reject) => {
        axios
          .get('/platforms/platforms')
          .then((res) => {
            if (res.success) {
              resolve(res)
              commit('setUserInfo', res.model)
            } else {
              reject(res)
            }
          })
          .catch((err) => {
            reject(err)
          })
      })
    }
  },
  getters
})
